//
//  ViewController.m
//  11207
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSArray *areaArr;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *path=[[NSBundle mainBundle]pathForResource:@"area1" ofType:@"plist"];
    self.areaArr=[[NSArray alloc]initWithContentsOfFile:path];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.areaArr.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary *dic=[[NSDictionary alloc]init];
    dic=self.areaArr[section];
    NSArray *arr=[NSArray array];
    arr=dic[@"Cities"];
    return arr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
    NSDictionary *dic=[[NSDictionary alloc]init];
    dic=self.areaArr[indexPath.section];
    NSArray *arr=[NSArray array];
    arr=dic[@"Cities"];
    cell.textLabel.text=arr[indexPath.row][@"city"];
    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    NSDictionary *dic=[[NSDictionary alloc]init];
    dic=self.areaArr[section];
    NSString *string=[[NSString alloc]init];
    string=dic[@"State"];
    return string;
}

- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    NSMutableArray *arrM=[[NSMutableArray alloc]init];
    NSString *string=[[NSString alloc]init];
    for (NSDictionary *dic in self.areaArr) {
        string=dic[@"State"];
        [arrM addObject:string];
    }
    return arrM;
}

@end
